This invention relates generally to multi-threaded computing environments, and more particularly to optimistic recyclable locking using complex locks for such environments.
Traditionally, computing environments in which computer programs are run have been single threaded. This means that only one task can be run within the computing environment at a time. This places constraints on both users and programs. A user for im example, is thus able to only run one program at a time. Similarly, a program is only able to run a single task, or thread, at a time.
Therefore, computing environments have been created that are multi-threaded. A user, is thus typically able to run more than one computer program in such environments at a single time, for example, both a word processing program and a spreadsheet program. Similarly, a program is in such environments usually able to run multiple threads or tasks concurrently, for example, a spreadsheet program can calculate a complex formula that may take minutes to complete while concurrently permitting the user to still continue editing a spreadsheet.
A problem arises, however, when two threads, either of the same or different programs, attempt to access the same data object (which may in a non-limiting and nonexclusive sense be defined as a software component) at the same time, where exclusive access to the object is required by one or both of these threads. Such concurrent access of the same object may result in corruption of programs"" data structures, ultimately causing the computer to crash. Therefore, when a given thread accesses an object, generally it is provided a lock on that object, for example, utilizing a lock object so that other threads can only acquire limited rights to the object until the given thread is finished with using the object. For instance, to improve thread throughput, it may be desirable to implement Read-Write locks, allowing for multiple threads to read the data structure, but only one thread modifying it. Another example may be a SQL database, in which appending is a very common situation, and thus it is desirable to make it a non-blocking procedure, which is often done by implementing a complex lock structure.
Locking mechanisms may be inefficient, however. If a lock object exists for every object within a given computing environment, or system, the result is a doubling of the number of objects within the system just to enable objects to be locked. Such an approach is thus an inefficient use of resources, both in terms of memory to store the lock objects, as well as the overhead to maintain these objects. For these and other reasons, there is a need for the present invention.
The above-identified problems, shortcomings and disadvantages with the prior art, as well as other problems, shortcoming and disadvantages, are solved by the present invention, which will be understood by reading and studying the specification and the drawings. In one embodiment, a system includes at least one thread, a pool of locks, at least one object, and a recyclable locking mechanism. Each object has an associated variable. The mechanism associates a complex lock with an object using the associated variable of the object as a pointer, upon a first request by a thread. All operations can be expressed using Win32 API""s thus providing for portable implementation on the prevalent software operating systems.
Thus, embodiments of the invention provide for advantages not found in the prior art. The number of complex locks can be much less than the number of objects in the system. When a thread desires to use an object, in one embodiment it sends a request to the recyclable locking mechanism, which then associates a lock from the pool of locks to the desired object. When the thread is finished with the object, and no other threads require use of the object, the associated lock is recycled for reuse.
The invention includes systems, methods, computers, and computer-readable media of varying scope. Besides the embodiments, advantages and aspects of the invention described here, the invention also includes other embodiments, advantages and aspects, as will become apparent by reading and studying the drawings and the following description.